/*****************************************************************************/
/*!	\file		LocalData.c
 *	\brief		C Source code file for the YX-PIS Example
 *	\par		Dalian Yunxing Tech Co., Ltd.
 *
 *				Dalian, China
 *				Phone   : +86 (411) 8825 4852
 *				Email   : yx@yunxing.tech
 */
/*****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "LocalData.h"

/* CSWI */
eDbPosValues CSWIStVal = DBPOS_OFF;

/* GGIO */
Boolean GGIOStVal1 = FALSE;
Boolean GGIOStVal2 = FALSE;
Boolean GGIOStVal3 = FALSE;
Boolean GGIOStVal4 = FALSE;

/* TTNS */
Float32 TTNSTnsSv1Magf = 0;
Float32 TTNSTnsSv2Magf = 0;
Float32 TTNSTnsSv3Magf = 0;

/* MMXU */
S32 MMXUPhsAMagi = 0;
S32 MMXUPhsBMagi = 0;
S32 MMXUPhsCMagi = 0;

/* IARC */
S32 MaxNumRcd = 0;
S32 OpMod = 0;
S32 MemFull = 0;

/* PDIF */
CrvPts PDIFCrvPts[SIZE_OF_PDIF_ARRAY] = { {0} };

/*Error String */
char strError[SIZE_OF_ERROR_STRING] = { 0 };

eDbPosValues GetCSWIStVal()
{
	return CSWIStVal;
}

eDbPosValues SetCSWIStVal(eDbPosValues stVal)
{
	// ensure that the DBPos value is valid
	switch (stVal) {
	case DBPOS_INTERMEDIATE:
		CSWIStVal = DBPOS_INTERMEDIATE;
		break;
	case DBPOS_OFF:
		CSWIStVal = DBPOS_OFF;
		break;
	case DBPOS_ON:
		CSWIStVal = DBPOS_ON;
		break;
	case DBPOS_BAD:
		CSWIStVal = DBPOS_BAD;
		break;
	}

	return CSWIStVal;
}

Boolean GetGGIOStVal(int index)
{
	switch (index) {
	case 1:
		return GGIOStVal1;
	case 2:
		return GGIOStVal2;
	case 3:
		return GGIOStVal3;
	case 4:
		return GGIOStVal4;
	default:
		return FALSE;
	}
}

Boolean SetGGIOStVal(Boolean stVal, int index)
{
	switch (index) {
	case 1:
		GGIOStVal1 = stVal;
		break;
	case 2:
		GGIOStVal2 = stVal;
		break;
	case 3:
		GGIOStVal3 = stVal;
		break;
	case 4:
		GGIOStVal4 = stVal;
		break;
	}
	return stVal;
}

Float32 GetTTNSTnsSv1Magf()
{
	return TTNSTnsSv1Magf;
}

Float32 GetTTNSTnsSv2Magf()
{
	return TTNSTnsSv2Magf;
}

Float32 GetTTNSTnsSv3Magf()
{
	return TTNSTnsSv3Magf;
}

Float32 SetTTNSTnsSv1Magf(Float32 inMagf)
{
	TTNSTnsSv1Magf = inMagf;
	return TTNSTnsSv1Magf;
}

Float32 SetTTNSTnsSv2Magf(Float32 inMagf)
{
	TTNSTnsSv2Magf = inMagf;
	return TTNSTnsSv2Magf;
}

Float32 SetTTNSTnsSv3Magf(Float32 inMagf)
{
	TTNSTnsSv3Magf = inMagf;
	return TTNSTnsSv3Magf;
}

S32 GetMaxNumRcd()
{
	return MaxNumRcd;
}

S32 GetOpMod()
{
	return OpMod;
}

S32 GetMemFull()
{
	return MemFull;
}

S32 SetMaxNumRcd(S32 inVal)
{
	MaxNumRcd = inVal;
	return MaxNumRcd;
}

S32 SetOpMod(S32 inVal)
{
	OpMod = inVal;
	return OpMod;
}

S32 SetMemFull(S32 inVal)
{
	MemFull = inVal;
	return MemFull;
}

S32 GetMMXUPhsAMagi()
{
	return MMXUPhsAMagi;
}

S32 SetMMXUPhsAMagi(S32 inPhsMagi)
{
	MMXUPhsAMagi = inPhsMagi;

	return MMXUPhsAMagi;
}

S32 GetMMXUPhsBMagi()
{
	return MMXUPhsBMagi;
}

S32 SetMMXUPhsBMagi(S32 inPhsMagi)
{
	MMXUPhsBMagi = inPhsMagi;

	return MMXUPhsBMagi;
}

S32 GetMMXUPhsCMagi()
{
	return MMXUPhsCMagi;
}

S32 SetMMXUPhsCMagi(S32 inPhsMagi)
{
	MMXUPhsCMagi = inPhsMagi;

	return MMXUPhsCMagi;
}

CrvPts GetPDIFCrvPts(S8 index)
{
	CrvPts returnVal = { 0 };

	// make sure the index is not out of range
	if ((index >= 0) && (index < SIZE_OF_PDIF_ARRAY)) {
		returnVal.xVal = PDIFCrvPts[index].xVal;
		returnVal.yVal = PDIFCrvPts[index].yVal;
	}

	return returnVal;
}

CrvPts SetPDIFCrvPts(S8 index, CrvPts crvPts)
{
	CrvPts returnVal = { 0 };

	// make sure the index is not out of range
	if ((index >= 0) && (index < SIZE_OF_PDIF_ARRAY)) {
		PDIFCrvPts[index].xVal = crvPts.xVal;
		PDIFCrvPts[index].yVal = crvPts.yVal;

		returnVal.xVal = PDIFCrvPts[index].xVal;
		returnVal.yVal = PDIFCrvPts[index].yVal;
	}

	return returnVal;
}

char* GetErrorString()
{
	return strError;
}

char* SetErrorString(char* errorString, U16 length)
{
	char* returnVal = NULL;

	/* Validate inputs */
	if (errorString && (length <= SIZE_OF_ERROR_STRING)) {
		memset(strError, 0, SIZE_OF_ERROR_STRING);	// set the string to 0

		memcpy(strError, errorString, length);	// copy the new error string
	}

	return returnVal;
}
